<template>
	<!-- <view  class="cashrecord" > -->
	<view class="cashrecord" id="cashrecord" @scroll='scroll'>
		<!-- bgcolor="#FD9031" -->
		<title class="title" id="title" :center="true" title="提现记录" iconSize="38" bgcolor="linear-gradient(45deg, #f43f3b, #ec008c)" 
			 @titleHeight='titleHeight' color="#FFF" @to-click="toBack(1)"
			icon="/static/img/other/to-back.png">
		</title>
		<view class="cashrecord_body" :style="{'padding-top':paddingTop + 'px'}">
			<view id="picker" class="cashrecord_picker">
				<view class="type" @click="cliToMenu(0)">
					<text> {{picker.type.title}}</text>
					<u-icon v-if='!picker.type.isShow' size="18" name="arrow-down-fill" style="margin-left: 8rpx;">
					</u-icon>
					<u-icon v-else size="18" name="arrow-up-fill" style="margin-left: 8rpx;"></u-icon>
				</view>
				<view class="range" @click="cliToMenu(1)">
					<text> {{picker.range.title}}</text>
					<u-icon v-if='!picker.range.isShow' size="18" name="arrow-down-fill" style="margin-left: 8rpx;">
					</u-icon>
					<u-icon v-else size="18" name="arrow-up-fill" style="margin-left: 8rpx;"></u-icon>
				</view>

				<!-- type的弹出层 -->
				<view class="type_pupop" v-if='picker.type.isShow'>
					<view class="sub_title" v-for="(item,i) in picker.type.other" :key='i'>
						<view :class="['fl',i==picker.type.current ? 'red':'']" @click="chooseItem(0,i)">
							<text>{{item}}</text>
							<u-icon v-if="i == picker.type.current" size="30" name="checkbox-mark"
								style="margin-left: 8rpx;"></u-icon>
						</view>
					</view>
				</view>
				<!-- range 的弹出层 -->
				<view class="range_pupop" v-if='picker.range.isShow'>
					<view class="businessTime">
						交易时间
						<view class="all_title">
							<view class="sub_title" v-for="(item,i) in picker.range.other" :key='i'>
								<button class="botton" @click="chooseItem(1,i)">
									{{item}}
								</button>
							</view>
						</view>

					</view>
					<view class="custom">
						自定义
						<view class="chooseTime">
							<view class="chooseTime_title">
								<view class="d">
									<picker mode="date" :value="data" fields="day" @change="bindChange($event,0)"
										:start="picker.date.range[0]" :end="picker.date.range[1]">
										<view class="condition_right_but">
											{{picker.date.start}}
											<u-icon size="18" name="arrow-down-fill" style="margin-left: 8rpx;">
											</u-icon>
										</view>
									</picker>
								</view>
								<text> -</text>
								<view class="d">
									<picker mode="date" :value="data" fields="day" @change="bindChange($event,1)"
										:start="picker.date.range[0]" :end="picker.date.range[1]">
										<view class="condition_right_but">
											{{picker.date.end}}
											<u-icon size="18" name="arrow-down-fill" style="margin-left: 8rpx;">
											</u-icon>
										</view>
									</picker>
								</view>
							</view>

						</view>
					</view>
					<button type="default" class="btn" @click="confirm">确定</button>
				</view>
			</view>

			<!-- 内容 -->
			<view id="content" class="content">
				<view class="content_all" v-for="(item,index) in contentList" :key="index">
					<view class="content_left">
						<view class="type view">
							支付宝
						</view>
						<text class="text">{{item.created_at}}</text>
					</view>
					<view class="content_right">
						<view class="jine view" :class="item.status == 0 ? 'red':'blue'">
							￥{{item.price}}
						</view>
						<text v-if="item.status == 0" class="text">提现成功</text>
						<text v-else-if="item.status == 1" class="text">提现失败</text>
					</view>
				</view>
			</view>

			<!-- 遮罩层 -->
			<view id="mask" :style="{height : height}"
				v-show="picker.type.isShow == true || picker.range.isShow == true" class="mask" @click="cliMask">
			</view>
		</view>
	</view>
</template>

<script>
	import moment from 'moment'
	import title from '@/pages/components/title.vue'
	export default {

		data() {
			return {
				paddingTop: '',
				height: '', //遮罩层的高度
				limit: 12,
				offset: 0,
				isLoad: true,
				picker: {
					type: {
						title: "全部类型",
						// other: ['全部类型', '零钱提现', '出票收入', '系统扣除'],
						other: ['支付宝'],
						current: 0,
						isShow: false
					},
					range: {
						title: "时间范围",
						other: ['近一月', '近三月', '近半年', '近一年'],
						current: 0,
						isShow: false
					},
					date: {
						showPicker: false,
						range: ['2017.01.01', '2019.01.31'],
						// 开始时间
						start: '',
						// 结束时间
						end: ''
					}
				},
				contentList: [],
			}
		},
		onLoad() {
			this.getMyCash()
			this.getTime()
		},
		onReachBottom() {
			this.offset = this.offset + 12
			this.getMyCash()
		},
		onPageScroll(e) {
			let _this = this
			let content = uni.createSelectorQuery().select('#content')
			content.boundingClientRect((data) => {}).exec((res) => {
				_this.height = res[0].height + 129 + 'px'
			})
		},
		methods: {
			// 接收title的高度
			titleHeight(data){
				this.paddingTop = data.height
			},
			// 日期范围选择
			// i = 0,开始时间， i =1 结束时间
			bindChange(e, i) {
				console.log(e, i)
				// this.data = e.detail.value;
				if (i == 0) {
					this.picker.date.start = e.detail.value.replace(/-/g, '.')
				} else {
					this.picker.date.end = e.detail.value.replace(/-/g, '.')
				}
				// console.log(this.picker.date.start, 'fdssafdasfdasdf', this.picker.date.end)
			},
			// 获取时间
			getTime() {
				let date = new Date();
				let year = date.getFullYear(); //获取完整的年份(4位)
				let month = date.getMonth() * 1 + 1; //获取当前月份(0-11,0代表1月)
				let day = date.getDate(); //获取当前日(1-31)
				let time = year + '.' + month + '.' + day
				let beforeTime = moment().subtract('days', 90).format('YYYY.MM.DD')
				// this.picker.date.range[0] = beforeTime
				this.picker.date.start = beforeTime
				this.picker.date.range[1] = this.picker.date.end = time
				// console.log(this.picker.date.range[0], this.picker.date.range[1])
			},
			// 跳转
			toBack(i) {
				uni.navigateBack({
					delta: i
				})
			},
			// 请求提现数据
			getMyCash(data = {}) {
				if (this.isLoad) {
					let cash_type = 0
					let start = ""
					let end = ""
					data = {
						limit: this.limit,
						offset: this.offset,
						cash_type: cash_type,
					}
					// 时间范围的条件赋值
					if (this.picker.range.title != '时间范围') {
						if (this.picker.range.title == '近一月') {
							start = moment().subtract('days', 30).format('YYYY-MM-DD')
							end = moment().format("YYYY-MM-DD")
							console.log(start + '---' + end)
						} else if (this.picker.range.title == '近三月') {
							start = moment().subtract('days', 90).format('YYYY-MM-DD')
							end = moment().format("YYYY-MM-DD")
							console.log(start + '---' + end)
						} else if (this.picker.range.title == '近半年') {
							start = moment().subtract('days', 180).format('YYYY-MM-DD')
							end = moment().format("YYYY-MM-DD")
							console.log(start + '---' + end)
						} else if (this.picker.range.title == '近一年') {
							start = moment().subtract('days', 365).format('YYYY-MM-DD')
							end = moment().format("YYYY-MM-DD")
							console.log(start + '---' + end)
						} else {
							let a = this.picker.range.title.split('-')
							start = a[0].replace(/\./g, '-')
							end = a[1].replace(/\./g, '-')
						}
						data.start = start
						data.end = end
					}
					this.$api.getMyCash(data).then(res => {
						if (res) {
							if (res.data.data.length > 0) {
								this.contentList = [...this.contentList, ...res.data.data]
								// console.log(this.contentList)
							} else {
								this.isLoad = false
								uni.showToast({
									title: "没有数据了",
									icon: 'none'
								})
							}
						}
					})
				}
			},
			// 点击确认按钮
			confirm() {
				this.picker.range.isShow = false
				if (!moment(this.picker.date.start).isBefore(this.picker.date.end)) {
					let temp = this.picker.date.start
					this.picker.date.start = this.picker.date.end
					this.picker.date.end = temp
				}
				this.picker.range.title = this.picker.date.start + '-' + this.picker.date.end.replace(/\//g, '.')
				this.offset = 0
				this.contentList = []
				this.isLoad = true
				this.getMyCash()
			},
			// 打开下拉菜单
			cliToMenu(index) {
				if (index == 0) {
					if (this.picker.range.isShow) {
						this.picker.range.isShow = false
					}
					this.picker.type.isShow = !this.picker.type.isShow
				} else {
					if (this.picker.type.isShow) {
						this.picker.type.isShow = false
					}
					this.picker.range.isShow = !this.picker.range.isShow
				}
			},
			// 选择条件
			// mold 0是type,1是range
			chooseItem(mold, index) {
				if (mold == 0) {
					this.picker.type.current = index
					this.picker.type.title = this.picker.type.other[index]
					this.picker.type.isShow = false
				} else {
					this.picker.range.current = index
					this.picker.range.title = this.picker.range.other[index]
					this.picker.range.isShow = false
				}
				this.offset = 0
				this.isLoad = true
				this.contentList = []
				this.getMyCash()
			},
			// 点击遮罩层
			cliMask() {
				this.picker.type.isShow = false
				this.picker.range.isShow = false
			},
		},
		components: {
			title
		}
	}
</script>

<style lang="scss" scoped>
	.cashrecord {
		width: 100vw;
		height: 100vh;

		.title {
			z-index: 999;
		}

		.cashrecord_body {
			padding-top: 125rpx;
			position: relative;
			width: 100%;
			height: 100%;

			.mask {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100vh;
				z-index: 777;
				background: rgba(0, 0, 0, .2);
			}

			.cashrecord_picker {
				position: fixed;
				z-index: 999;
				display: grid;
				grid-template-columns: auto auto;
				grid-template-rows: auto;
				justify-items: center;
				align-items: center;
				width: 100vw;
				height: 100rpx;
				font-size: 26rpx;
				font-weight: 400;
				color: #666666;
				background-color: white;
				border-bottom: 1px solid #EBEDF0;
			}

			.content {
				margin-top: 100rpx;
				padding: 0 24rpx 0 24rpx;
				position: relative;
				z-index: 10;

				.content_all {
					padding: 21rpx 0 21rpx 0;
					display: flex;
					justify-content: space-between;
					border-bottom: 1px solid #F1F1F1;

					.text {
						font-size: 24rpx;
						color: #999999;
					}

					.view {
						font-size: 30rpx;
						color: #333333;
					}

					.red {
						color: #EF3B5D;
					}

					.blue {
						color: #1796CF;
					}
				}
			}

			.type_pupop {
				padding: 0 25rpx;
				// position: fixed;
				// top: 225rpx;
				position: absolute;
				top: 100rpx;
				background-color: #FFFFFF;
				z-index: 888;
				width: 100%;

				.fl {
					display: flex;
					justify-content: space-between;
					font-size: 26rpx;
					font-weight: 400;
					color: #666666;
					margin: 30rpx 0;
				}
			}

			.range_pupop {
				// position: fixed;
				// top: 225rpx;
				position: absolute;
				top: 100rpx;
				background-color: white;
				width: 100%;
				z-index: 888;
				padding: 35rpx;
				font-size: 26rpx;
				color: #666666;

				.businessTime {
					margin-bottom: 50rpx;

					.all_title {
						display: grid;
						grid-template-rows: auto;
						grid-template-columns: auto auto auto auto;
						justify-content: start;
						grid-gap: 20rpx;
						margin-top: 30rpx;

						.sub_title {
							.botton {
								width: 150rpx;
								padding-left: 14rpx;
								padding-right: 14rpx;
								cursor: pointer;
								font-size: 26rpx;
								border-color: black;
								border-radius: 5rpx;
							}
						}
					}
				}

				.custom {
					.chooseTime {
						.chooseTime_title {
							margin-top: 30rpx;
							display: grid;
							grid-template-columns: auto auto auto;
							grid-template-rows: auto;

							.d {
								width: 220rpx;
								height: 60rpx;
								border-radius: 8rpx;
								text-align: center;
								line-height: 60rpx;
								background-color: #f0f0f0;
							}
						}

					}

				}

				.btn {
					width: 650rpx;
					height: 88rpx;
					background: linear-gradient(91deg, #EF4447 0%, #EF298A 100%);
					border-radius: 44px;
					font-weight: 500;
					font-size: 32rpx;
					color: #FEFEFE;
					margin-top: 40rpx;
				}
			}


		}
	}

	.red {
		color: red !important;
	}
</style>
